{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f8dcc1e1",
   "metadata": {},
   "source": [
    "# 云平台"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4dee33ae",
   "metadata": {},
   "source": [
    "在使用“天衍”量子计算云平台进行量子计算任务之前，用户需要注册账号并获取对应的访问密钥。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b6019a5",
   "metadata": {},
   "source": [
    "<img src='./images/dashboard.jpg' width='800px'>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d86c357",
   "metadata": {},
   "source": [
    "## 1. 云平台"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03209596",
   "metadata": {},
   "source": [
    "设备列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca49ad61",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computers:\n",
      "------------------\n",
      "ID                  费用      运行状态        代码\n",
      "3                   free      running        tianyan_sw     \n",
      "4                   free      running        tianyan_s      \n",
      "7                   free      running        tianyan_tn     \n",
      "8                   free      running        tianyan_tnn    \n",
      "9                   free      running        tianyan_sa     \n",
      "10                  free      running        tianyan_swn    \n",
      "1764555284795101186 free      calibration    tianyan176     \n",
      "1764555284795101187 free      running        tianyan176-2   \n",
      "1764555284795101188 free      running        tianyan24      \n",
      "1882266438434926594 paid      running        tianyan504     \n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from cqlib import TianYanPlatform\n",
    "\n",
    "# 手动设置登录密钥\n",
    "login_key = os.getenv(\"LOGIN_KEY\", '')\n",
    "pf = TianYanPlatform(login_key=login_key)\n",
    "\n",
    "#获取可用量子设备列表\n",
    "computers = pf.query_quantum_computer_list()\n",
    "\n",
    "print('Computers:')\n",
    "print('------------------')\n",
    "print(f\"{'ID':<20}{'费用':<8}{'运行状态':<12}{'代码':<1}\")\n",
    "for item in computers:\n",
    "    print(f\"{str(item[0]):<20}{item[1]:<10}{item[2]:<15}{item[3]:<15}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04cf1219",
   "metadata": {},
   "source": [
    "### 1.1 选择设备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2e7809ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "pf = TianYanPlatform(login_key=login_key, machine_name=\"tianyan176-2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11146ff0",
   "metadata": {},
   "source": [
    "也可以通过以下方式切换当前设备："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7a89ec84",
   "metadata": {},
   "outputs": [],
   "source": [
    "pf.set_machine(\"tianyan176\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fa6f516",
   "metadata": {},
   "source": [
    "### 1.2 任务管理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a3113ae",
   "metadata": {},
   "source": [
    "用于创建量子线路、提交任务至云平台并获取运行结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f3a422c",
   "metadata": {},
   "source": [
    "（1）创建线路"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a512d1ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "线路：\n",
      "                \n",
      " Q0: ───H──■──M─\n",
      "           │    \n",
      " Q7: ──────X──M─\n",
      "                \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from cqlib import  Circuit, TianYanPlatform\n",
    "\n",
    "circuit = Circuit([0,7])\n",
    "circuit.h(0)\n",
    "circuit.cx(0, 7)\n",
    "circuit.measure_all()\n",
    "print(f'线路：\\n{circuit.draw()}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5a3ae23",
   "metadata": {},
   "source": [
    "（2）实例化平台连接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9f5b388a",
   "metadata": {},
   "outputs": [],
   "source": [
    "pf = TianYanPlatform(login_key=login_key, machine_name=\"tianyan176-2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa9b1b6d",
   "metadata": {},
   "source": [
    "（3）提交任务"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2cdcf2df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "query_id: ['1913123896338644993']\n"
     ]
    }
   ],
   "source": [
    "query_id = pf.submit_experiment(circuit.qcis, num_shots=10)\n",
    "\n",
    "print(f'query_id: {query_id}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d29a52e",
   "metadata": {},
   "source": [
    "此外，Cqlib还支持批量提交实验任务，适用于线路结构基本一致、测量比特一致，仅部分参数不同的场景。每次提交任务的数量上限为 50 个。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "456e198a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "result: {'code': 0, 'message': None, 'data': {'query_ids': ['1913049815773839361', '1913049816117772290']}, 'success': True}\n",
      "query_ids: ['1913049815773839361', '1913049816117772290']\n"
     ]
    }
   ],
   "source": [
    "query_ids = pf.submit_experiment([circuit.qcis, circuit.qcis], num_shots=1000)\n",
    "\n",
    "print(f'query_ids: {query_ids}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eeaef6a7",
   "metadata": {},
   "source": [
    "（4）查询结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b206b4b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task: \t1913125668021043201: \t\n",
      "概率：\t{\"1110\":0.065,\"1011\":0.055,\"1000\":0.06,\"1010\":0.08,\"0010\":0.06,\"0101\":0.06,\"0000\":0.07,\"1101\":0.05,\"0011\":0.055,\"0110\":0.035,\"1001\":0.075,\"0111\":0.06,\"1100\":0.065,\"1111\":0.085,\"0100\":0.065,\"0001\":0.06}\t\n",
      "采样数据：\t[[0, 1, 2, 3], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 0, 0], [1, 1, 1, 0], [1, 0, 1, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1], [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 1], [1, 0, 1, 0], [0, 0, 1, 0], [1, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 1], [0, 1, 0, 0], [1, 0, 1, 1], [1, 1, 0, 1], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1], [1, 0, 0, 0], [0, 0, 1, 0], [1, 0, 0, 1], [1, 0, 1, 1], [0, 0, 0, 1], [0, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0], [1, 0, 0, 1], [0, 1, 0, 1], [1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 0, 0], [1, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 1, 1, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [1, 1, 0, 1], [1, 1, 0, 0], [1, 0, 0, 1], [1, 0, 1, 1], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 0, 0], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 1, 1, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 0, 1], [1, 0, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 0], [0, 1, 1, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1], [0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 0, 1], [0, 1, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1], [1, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0], [0, 1, 0, 1], [0, 1, 0, 0], [0, 1, 0, 0], [1, 1, 0, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 1, 0, 1], [0, 0, 1, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1], [1, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 1], [1, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [0, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 1], [0, 1, 0, 0], [0, 0, 1, 1], [1, 1, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 1], [0, 0, 1, 0], [1, 1, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1], [1, 1, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0], [1, 1, 1, 1], [0, 1, 0, 0], [0, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0], [1, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 0], [1, 1, 1, 0], [0, 1, 0, 1], [1, 1, 1, 0]]\t\n"
     ]
    }
   ],
   "source": [
    "data = pf.query_experiment(query_id)\n",
    "for item in data:\n",
    "    print(f\"task: \\t{item['experimentTaskId']}: \\t\\n\"\n",
    "          f\"概率：\\t{item['probability']}\\t\\n\"\n",
    "          f\"采样数据：\\t{item['resultStatus']}\\t\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "439ec0b7",
   "metadata": {},
   "source": [
    "注意: 采样结果中的第一位表示数据比特的编号。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "645b4c88",
   "metadata": {},
   "source": [
    "### 1.3 物理机配置信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "260dbcfd",
   "metadata": {},
   "source": [
    "天衍量子计算云平台提供了查询物理量子计算机配置信息的接口，用户可以通过 Cqlib 获取包括：\n",
    "\n",
    "- 校准时间\n",
    "- 拓扑结构\n",
    "- 量子门保真度\n",
    "- 测量误差率\n",
    "- 其他等关键指标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "22a04542",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "config: dict_keys(['calibrationTime', 'computerId', 'disabledCouplers', 'disabledQubits', 'overview', 'qubit', 'readout', 'status', 'twoQubitGate'])\n"
     ]
    }
   ],
   "source": [
    "config = pf.download_config()\n",
    "print(f'config: {config.keys()}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "173439b8",
   "metadata": {},
   "source": [
    "### 1.4 读取误差校正（适用于物理机）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24c29f3f",
   "metadata": {},
   "source": [
    "对于真实的量子计算设备（不适用于仿真机），Cqlib 支持读取校正功能：根据物理设备的配置对实验测量结果进行概率调整，以获得更接近真实的输出分布。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "efbe501c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task 1913049815102750722: {'00': np.float64(0.47132960618731773), '01': np.float64(0.0017436971693695477), '10': np.float64(0.022971022341498705), '11': np.float64(0.5039556743018141)}\n"
     ]
    }
   ],
   "source": [
    "data = pf.query_experiment(query_id, readout_calibration=True)\n",
    "for item in data:\n",
    "    print(f\"task {item['experimentTaskId']}: {item['probability']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45875bf8",
   "metadata": {},
   "source": [
    "当 `readout_calibration = True` 时，系统会自动下载当前设备的配置文件，这将会增加一定的网络开销。建议提前手动加载配置文件以提升效率。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "145ebddb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task 1913049815102750722: {'00': np.float64(0.47132960618731773), '01': np.float64(0.0017436971693695477), '10': np.float64(0.022971022341498705), '11': np.float64(0.5039556743018141)}\n"
     ]
    }
   ],
   "source": [
    "config = pf.download_config()\n",
    "data = pf.query_experiment(query_id, readout_calibration=True, machine_config=config)\n",
    "for item in data:\n",
    "    print(f\"task {item['experimentTaskId']}: {item['probability']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f25370e",
   "metadata": {},
   "source": [
    "## 2. 量子计算机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c55fda51",
   "metadata": {},
   "source": [
    "量子计算真机基于量子叠加、纠缠等原理构建的物理系统，能直接操控量子比特（Qubit）执行运算。相较经典计算机具有潜在的指数级加速能力。\n",
    "\n",
    "目前云平台部署了 4 台量子计算机，分别是 `天衍-176`,、`天衍-176-Ⅱ`、`天衍-24`、`天衍-504`。\n",
    "\n",
    "|  设备       | 代码          | 数据比特数 | 耦合比特数  | 平均 T1 (μs) | 平均 T2(μs) |\n",
    "|------------|----------------|-------|----------------|------|------|\n",
    "| 天衍-176    | tianyan176    | 66    |  110             | 33.14 | 3.67|\n",
    "| 天衍-176-Ⅱ | tianyan176-2  | 66    |  110             | 23.4   | 3.38 |\n",
    "| 天衍-24     | tianyan24     | 24    |  34             |  44.65  |   14.13 |\n",
    "| 天衍-504    | tianyan504    | 504   |  503              | 63.2  |  14.33|\n",
    "\n",
    "其中，综合性能最优的是 `天衍-176-Ⅱ`。\n",
    "\n",
    "注意：云平台每 30 分钟进行一次设备校准。校准期间可正常提交任务，但任务需等待校准完成后才可开始执行。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad92a0df",
   "metadata": {},
   "source": [
    "## 3. 仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ddfd18f",
   "metadata": {},
   "source": [
    "量子计算仿真机是基于经典计算资源，用于模拟量子系统行为和量子算法运行的工具。它广泛应用于：\n",
    "- 探索量子计算基本原理\n",
    "- 验证和调试量子算法\n",
    "- 支撑量子芯片设计优化\n",
    "\n",
    "目前天衍量子计算云平台共开放了 6 种高性能仿真机，分别适配于不同的仿真需求场景。\n",
    "\n",
    "\n",
    "|   名称         |    代码   |  最大比特数 |      描述       |\n",
    "|------------------|----------|-----------|-------------|\n",
    "| 天衍-全振幅        | tianyan_sw | 36      |  全振幅状态向量仿真机 |\n",
    "| 天衍-稳定子        | tianyan_s | 5000      |  稳定子仿真机 |\n",
    "| 天衍-张量网络       | tianyan_tn | 30      |  张量网络仿真机 |\n",
    "| 天衍-单振幅        | tianyan_sa | 200      |  单振幅仿真机 |\n",
    "|天衍-密度矩阵带噪声 | tianyan_swn | 18      |  密度矩阵带噪声仿真机 |\n",
    "\n",
    "\n",
    "当前，全振幅仿真机已支持最多 30 个数据比特的任务调用。如需要模拟超过 30 比特的量子线路，请联系 “天衍”量子计算云平台 [tianyan@chinatelecom.cn ](mailto:tianyan@chinatelecom.cn )。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d710317",
   "metadata": {},
   "source": [
    "#### 3.1 全振幅仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93e4764b",
   "metadata": {},
   "source": [
    "全振幅状态向量仿真机是一种高精度模拟方法，它通过显式储存并演化一个包含2ⁿ个复数的量子态向量，精确再现n比特系统中每一步的量子演化过程。\n",
    "\n",
    "“天衍-全振幅”仿真机支持 QCIS 指令集中的全部量子门，适用于各类通用量子线路的模拟需求。\n",
    "示例代码："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e91ce3b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task 1913124561366515714: \n",
      "概率：   {\"00\":0.53,\"11\":0.47}\n",
      "采样数据：[[0, 7], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1]]\n"
     ]
    }
   ],
   "source": [
    "pf.set_machine(\"tianyan_sw\")\n",
    "query_id = pf.submit_experiment(circuit.qcis, num_shots=200)\n",
    "data = pf.query_experiment(query_id)\n",
    "item = data[0]\n",
    "print(f\"task {item['experimentTaskId']}: \\n\"\n",
    "      f\"概率：   {item['probability']}\\n\"\n",
    "      f\"采样数据：{item['resultStatus']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "173f6d34",
   "metadata": {},
   "source": [
    "#### 3.2 稳定子仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18377564",
   "metadata": {},
   "source": [
    "稳定子仿真机是一种面向Clifford电路（如量子纠错码、量子保密传输等）的高效模拟方法。它通过稳定子群来表示和追踪量子态，将计算复杂度从指数级降至多项式级。\n",
    "\n",
    "“天衍-稳定子” 仿真机支持 `H`、`X`、`Y`、`Z`、`S`、`SD`、`CX`、`CZ`、`M` 量子门。\n",
    "示例代码："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4b2855a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task 1913124637853843458: \n",
      "概率：   {\"00\":0.49,\"11\":0.51}\n",
      "采样数据：[[0, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0]]\n"
     ]
    }
   ],
   "source": [
    "c2 = Circuit(2)\n",
    "c2.h(0)\n",
    "c2.h(1)\n",
    "c2.cz(0, 1)\n",
    "c2.h(1)\n",
    "c2.measure_all()\n",
    "\n",
    "pf.set_machine(\"tianyan_s\")\n",
    "query_id = pf.submit_experiment(c2.qcis, num_shots=200)\n",
    "data = pf.query_experiment(query_id)\n",
    "item = data[0]\n",
    "print(f\"task {item['experimentTaskId']}: \\n\"\n",
    "      f\"概率：   {item['probability']}\\n\"\n",
    "      f\"采样数据：{item['resultStatus']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c788856e",
   "metadata": {},
   "source": [
    "#### 3.3 张量网络仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c9ab5d1f",
   "metadata": {},
   "source": [
    "张量网络仿真机是一种基于经典计算的量子电路模拟方法，通过将量子态重构为可分解的张量网络，并利用其稀疏性特征，能够高效模拟具有特定结构的量子电路，尤其适用于低纠缠量子系统的近似模拟。\n",
    "\n",
    "“天衍-张量网络”仿真机支持 QCIS 指令集定义的全部量子门。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4ebdd0c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "task 1913124742157795330: \n",
      "概率：   {\"00\":0.48,\"11\":0.52}\n",
      "采样数据：[[0, 7], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0]]\n"
     ]
    }
   ],
   "source": [
    "pf.set_machine(\"tianyan_tn\")\n",
    "query_id = pf.submit_experiment(circuit.qcis, num_shots=200)\n",
    "data = pf.query_experiment(query_id)\n",
    "item = data[0]\n",
    "print(f\"task {item['experimentTaskId']}: \\n\"\n",
    "      f\"概率：   {item['probability']}\\n\"\n",
    "      f\"采样数据：{item['resultStatus']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "452c6951",
   "metadata": {},
   "source": [
    "#### 3.4 单振幅仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b931faac",
   "metadata": {},
   "source": [
    "单振幅仿真机是一种资源优化型量子模拟方法，支持对某一目标量子态的单个概率振幅进行动态计算，而非存储完整的量子态向量。这种方式通过以时间换空间，显著降低内存占用，适用于：\n",
    "- 稀疏输出量子线路\n",
    "- 特定态概率提取任务\n",
    "由于该方法仅关注单一振幅，因此无法提供全局量子态信息，也不支持测量门操作。\n",
    "\n",
    "“天衍-单振幅”仿真机支持 QCIS 定义的所有量子门（除测量门外），目标量子态需以整数形式给出，取值范围为[0，$2^n -1$] ，其中 n 为当前线路比特数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "bdfc003d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Task: 1913124982445277186\n",
      "量子态：   0.1767766952966368 + 0.0i\n"
     ]
    }
   ],
   "source": [
    "pf.set_machine(\"tianyan_sa\")\n",
    "\n",
    "c5 = Circuit(5)\n",
    "for i in range(5):\n",
    "    c5.h(i)\n",
    "\n",
    "query_id = pf.submit_experiment(c5.qcis, quantum_state=1)\n",
    "data = pf.query_experiment(query_id)\n",
    "item = data[0]\n",
    "print(f\"Task: {item['experimentTaskId']}\\n\"\n",
    "      f\"量子态：   {item['phase']}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c02287e6",
   "metadata": {},
   "source": [
    "#### 3.5 密度矩阵带噪声仿真机"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d50ca46",
   "metadata": {},
   "source": [
    "密度矩阵噪声仿真机是一种基于密度矩阵形式的量子模拟方法，结合了多种常见噪声模型（如退相干、门误差等），能够精确模拟量子混合态的演化过程。该模型适用于评估含噪量子硬件的实际表现，以及验证量子纠错策略的有效性。\n",
    "\n",
    "“天衍-密度矩阵带噪声”仿真机支持 QCIS 指令集中定义的全部量子门操作。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdbba093",
   "metadata": {},
   "source": [
    "噪声定义：\n",
    "\n",
    "|  名称 | 公式| 参数|  范围 | 应用规则 |  示例 |\n",
    "|------------|----------------------------|---------|--------------|------------|-------|\n",
    "| 比特翻转 | $E_0 = \\sqrt{\\rho } I = \\sqrt{\\rho }\\begin{bmatrix} 1 & 0 \\\\ 0  & 1\\end{bmatrix}$ <br> $E_1 = \\sqrt{1-\\rho } X = \\sqrt{1-\\rho }\\begin{bmatrix} 0 & 1 \\\\ 1  & 0\\end{bmatrix}$ | bitflip | [0, 1] | 0,1 |{\"id\":0, \"noise_type\":\"bitflip\",\"data\":{\"prob\":0.1}} |\n",
    "| 相位翻转 | $E_0 = \\sqrt{\\rho } I = \\sqrt{\\rho }\\begin{bmatrix} 1 & 0\\\\ 0  & 1\\end{bmatrix}$ <br> $E_1 = \\sqrt{1-\\rho } Z = \\sqrt{1-\\rho }\\begin{bmatrix} 1 & 0 \\\\ 0  & -1\\end{bmatrix}$ | phaseflip | [0, 1]  | 0,1| {\"id\":0, \"noise_type\":\"phaseflip\", \"data\":{\"prob\":0.1}} |\n",
    "| 比特相位翻转 | $E_0 = \\sqrt{\\rho } I = \\sqrt{\\rho }\\begin{bmatrix} 1 & 0 \\\\ 0  & 1\\end{bmatrix}$ <br> $E_1 = \\sqrt{1-\\rho } Y = \\sqrt{1-\\rho }\\begin{bmatrix} 0 & -i \\\\ i  & 0\\end{bmatrix}$ | phasebitflip | [0, 1]  | 0,1| {\"id\":0, \"noise_type\":\"phasebitflip\", \"data\":{\"prob\":0.1}} |\n",
    "| 退极化信道 | $\\sqrt{1-{\\frac{3\\rho }{4} I}} , \\frac{\\sqrt{\\rho } }{2} X, \\frac{\\sqrt{\\rho } }{2} Y, \\frac{\\sqrt{\\rho } }{2} Z $ | depolarizing | [0, 1]  | 0,1 | {\"id\":0, \"noise_type\":\"depolarizing\", \"data\":{\"prob\":0.1,\"num_qubits\":2}} |\n",
    "|泡利噪声| | pauli | 1. 可以作用于单比特或者双比特，num_qubits 属于 {1,2} <br> 2. 可以指定一个或者多个量子门（X/Y/Z/I），以及概率。<br> 3. 每个概率为 [0, 1] 内的浮点数，最多三位小数；所有概率之和为1  | 0,1| {\"id\":0, \"noise_type\":\"pauli\", \"data\":{ \"num_qubits\":1, \"ops\":[[\"x\",0.1],[\"yz\",0.9]]}} |\n",
    "| 阻尼 | 振幅阻尼<br>$E_0 = \\begin{bmatrix}1  & 0 \\\\ 0  & \\sqrt{1-\\rho } \\end{bmatrix}$ , $E_1 = \\begin{bmatrix}0  & \\sqrt{\\rho }  \\\\ 0  & 0\\end{bmatrix}$ <br> 相位阻尼 <br> $E_0 =  \\sqrt{\\rho } \\begin{bmatrix}1  & 0 \\\\ 0  & 1\\end{bmatrix}$ , $E_1 =  \\sqrt{1-\\rho } \\begin{bmatrix}1  & 0 \\\\ 0  & -1\\end{bmatrix}$ | damping | 振幅概率（amplitude_prob）: [0, 1]<br> 相位概率（phase_prob）: [0, 1] <br> 损耗状态（dissipation_state）: [0, 1]  | 0,1 |  {\"id\":0, \"noise_type\":\"damping\", \"data\":{\"amplitude_prob\":0.1, \"phase_prob\":0.1, \"dissipation_state\":0}} |\n",
    "|  读取 | $P = \\begin{bmatrix}\\rho (0\\mid 0)  & \\rho (1\\mid 0) \\\\ \\rho (0\\mid 1)  &\\rho (1\\mid 1)\\end{bmatrix}$ | readout | $ 2^n * 2^n$ 的矩阵，英文逗号分割，n为比特数量，n >= 1，矩阵内元素均为 >= 0 且 <= 1的浮点数，最多3位小数，矩阵每行之和为1。<br> 例如：[[0.2, 0.7],[0.1, 0.9]]|2 | {\"id\":0, \"noise_type\":\"readout\", \"data\":{\"prob\": \"[[0.8, 0.2], [0.2, 0.8]]\"}} |\n",
    "\n",
    "注：\n",
    "1. 每个噪声必须有一个独立不重复的 id，该编号在后续应用规则中将被引用。\n",
    "2. 参数 num_qubits 表示噪声适用的比特数：单比特噪声用 1 表示， 双比特噪声用 2 表示。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4394acb6",
   "metadata": {},
   "source": [
    "噪声应用规则：\n",
    "\n",
    "| 名称 | 类型|  说明 | 示例 |\n",
    "|---------|-----|----------|--------|\n",
    "|指定量子门和量子比特 |   0 | 指定量子门和量子比特列表 |{\"noise_id\":0,\"add_type\":0,\"gates\":[\"h\"],\"qubits\":[1,2]}|\n",
    "|针对所有比特位的指定量子门| 1  | 只要指定量子门，作用与所有比特。  | {\"noise_id\":0,\"add_type\":1,\"gates\":[\"h\",\"x\"]}|\n",
    "|针对某些比特位| 2 | 指定某些比特 |{\"noise_id\":0,\"add_type\":2,\"qubits\":[1,2]}|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed7009dd",
   "metadata": {},
   "source": [
    "使用示例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5a8649e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Task: 1913125668021043201\n",
      "概率：   {\"1110\":0.065,\"1011\":0.055,\"1000\":0.06,\"1010\":0.08,\"0010\":0.06,\"0101\":0.06,\"0000\":0.07,\"1101\":0.05,\"0011\":0.055,\"0110\":0.035,\"1001\":0.075,\"0111\":0.06,\"1100\":0.065,\"1111\":0.085,\"0100\":0.065,\"0001\":0.06}\n",
      "采样数据：[[0, 1, 2, 3], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 0, 0], [1, 1, 1, 0], [1, 0, 1, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1], [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 1], [1, 0, 1, 0], [0, 0, 1, 0], [1, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 1], [0, 1, 0, 0], [1, 0, 1, 1], [1, 1, 0, 1], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1], [1, 0, 0, 0], [0, 0, 1, 0], [1, 0, 0, 1], [1, 0, 1, 1], [0, 0, 0, 1], [0, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0], [1, 0, 0, 1], [0, 1, 0, 1], [1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 0, 0], [1, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 1, 1, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [1, 1, 0, 1], [1, 1, 0, 0], [1, 0, 0, 1], [1, 0, 1, 1], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 0, 0], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 1, 1, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 0, 1], [1, 0, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 0], [0, 1, 1, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1], [0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 0, 1], [0, 1, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1], [1, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0], [0, 1, 0, 1], [0, 1, 0, 0], [0, 1, 0, 0], [1, 1, 0, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 1, 0, 1], [0, 0, 1, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1], [1, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 1], [1, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [0, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 1], [0, 1, 0, 0], [0, 0, 1, 1], [1, 1, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 1], [0, 0, 1, 0], [1, 1, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1], [1, 1, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0], [1, 1, 1, 1], [0, 1, 0, 0], [0, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0], [1, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 0], [1, 1, 1, 0], [0, 1, 0, 1], [1, 1, 1, 0]]\n"
     ]
    }
   ],
   "source": [
    "# 定义噪声模型\n",
    "noise = [{\n",
    "    \"id\": 0,\n",
    "    \"noise_type\": \"bitflip\",\n",
    "    \"data\": {\"prob\": 0.1}\n",
    "},{\n",
    "    \"id\": 1,\n",
    "    \"noise_type\": \"phaseflip\",\n",
    "    \"data\": {\"prob\": 0.1}\n",
    "}]\n",
    "\n",
    "# 定义噪声应用规则\n",
    "rules = [\n",
    "    {\n",
    "        \"noise_id\": 0,\n",
    "        \"add_type\": 0,\n",
    "        \"gates\": [\"h\", \"x\"],\n",
    "        \"qubits\": [1, 2]\n",
    "    },\n",
    "    {\n",
    "        \"noise_id\": 1,\n",
    "        \"add_type\": 0,\n",
    "        \"gates\": [\"x\"],\n",
    "        \"qubits\": [2]\n",
    "    }\n",
    "]\n",
    "\n",
    "#构建并提交任务\n",
    "pf.set_machine(\"tianyan_swn\")\n",
    "\n",
    "c6 = Circuit(4)\n",
    "for i in range(4):\n",
    "    c6.h(i)\n",
    "    c6.x(i)\n",
    "c6.measure_all()\n",
    "\n",
    "query_id = pf.submit_experiment(c6.qcis, num_shots=200, noise=noise, rules=rules)\n",
    "data = pf.query_experiment(query_id)\n",
    "item = data[0]\n",
    "print(f\"Task: {item['experimentTaskId']}\\n\"\n",
    "      f\"概率：   {item['probability']}\\n\"\n",
    "      f\"采样数据：{item['resultStatus']}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cqlib3.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
